package com.zm.core.common.controller;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.zm.core.util.Json;
import com.jfinal.core.Controller;

public class BaseController extends Controller {

	public String inserted;
	public String updated;
	public String deleted;
	public String allrows;
	
	public String list2json(List list)
	{
		return Json.list2json(list);
	}
	public List obj2list(Object obj)
	{
		return Json.obj2list(obj);
	}
	public <T> List<T> obj2model(Class<T> t,Object obj)
	{
		List<T> models=new ArrayList<T>();
		try {
			Method method=t.getMethod("set", String.class,Object.class);
			List<Map<String, String>> list=obj2list(obj);
			
			for(Map<String, String> map : list)
			{
				T model=t.newInstance();
				for (String key : map.keySet())
				{
					method.invoke(model, key,map.get(key));
				}
				models.add(model);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return models;
	}

}
